package com.physics.mps.module.setting;

import com.physics.mps.entity.dto.AppParamEntity;
import com.physics.mps.entity.vo.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author mcsoft
 * @date 2023/09/18 11:30
 **/
@Api(tags = "app_param接口")
@RestController
@RequestMapping(value = "/param")
@RequiredArgsConstructor
public class AppParamController {
    private final AppParamService appParamService;

    @ApiOperation(value = "新增参数")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @PostMapping("/addParam")
    public ResponseResult addParam(@Validated @RequestBody AppParamEntity appParamEntity) {
        return ResponseResult.success(appParamService.save(appParamEntity));
    }

    @ApiOperation(value = "编辑参数")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @PostMapping("/editParam")
    public ResponseResult editParam(@Validated @RequestBody AppParamEntity appParamEntity) {
        return ResponseResult.success(appParamService.updateById(appParamEntity));
    }

    @ApiOperation(value = "删除参数")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @PostMapping("/deleteParam/{id}")
    public ResponseResult deleteParam(@PathVariable("id") String id) {
        return ResponseResult.success(appParamService.removeById(id));
    }
}
